package me.leiusual.sharing.pref

import android.content.Context
import me.leiusual.sharing.pref.impl.KDelegate
import javax.inject.Inject
import javax.inject.Singleton

/**
 * Create by leiusual on 2018/7/18
 */
@Singleton
class Token @Inject constructor(
    context: Context
) : AbstractPref(context) {

  var accessToken: String? by KDelegate.KString(sp)
  var tokenType: String? by KDelegate.KString(sp)
  var refreshToken: String? by KDelegate.KString(sp)
  var expiresIn: Long by KDelegate.KLong(sp) // ms 保存的失效时间点
  var scope: String? by KDelegate.KString(sp)

  // 有Token 且 还没有失效
  val isLogin: Boolean
    get() {
      return !accessToken.isNullOrBlank() && System.currentTimeMillis() < expiresIn - 1000
    }
}